<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@include file="mastertop.jsp"%>
<div class="line-title">
	<b></b>
</div>
<form action="${ctx}/common/skuselect/selectItem" method="post" id="selectItemForm">
<div class="form-inline clearfix form-label-120 filter-warp rect-fff">
		<input type="hidden" name="stockId" id="stockId" value="${model.stockId}" />
		<input type="hidden" name="categoryId" id="cateId" value="${model.categoryId}" />
		<input type="hidden" name="cateLevel" id="catLevel" value="${model.cateLevel}" />
		<input type="hidden" name="selectedItemIds" value="${model.selectedItemIds}" />

		<div class="form-group col-xs-6">
			<span class="form-label">润米内部编码</span>
			<input type="text" class="form-control form-control-200"  name="skuCode" value="${model.skuCode}">
		</div>
		<div class="form-group col-xs-6">
			<span class="form-label">商品69码</span>
			<input type="text" class="form-control form-control-200"  name="barCode" value="${model.barCode}">
		</div>
		<div class="form-group col-xs-6">
			<span class="form-label">SKU名称</span>
			<input type="text" class="form-control form-control-200"  name="skuName" value="${model.skuName}">
		</div>
		<div class="form-group col-xs-6">
			<span class="form-label">商品品牌</span>
			<select  name="brandId"  class="form-control form-control-200">
				<option value="" <c:if test="${model.brandId==null}">selected="selected"</c:if>>全部</option>
				<c:forEach items="${model.brands}" var="brand">
					<option value="${brand.id}" <c:if test="${model.brandId==brand.id}">selected="selected"</c:if>>${brand.brandName}</option>
				</c:forEach>
			</select>
		</div>
		<div class="form-group col-xs-6">
			<span class="form-label">商品类别</span>
			<input type="text" class="form-control form-control-200" name="catName" id="catName"
														onclick="showCategory()" autocomplete="off" id="catName"
														value="${model.catName}">
			<div id="treediv" class="treecategory" style="margin-left: 130px">

			</div>
		</div>
		<div class="form-group col-xs-6">
			<span class="form-label">供应商</span>
			<select  name="factoryId"  id="factoryId"  class="form-control form-control-200">
				<option value="" <c:if test="${model.factoryId==null}">selected="selected"</c:if>>全部</option>
				<c:forEach items="${model.factorys}" var="lo" varStatus="itemStatus">
					<option value="${lo.id}" <c:if test="${model.factoryId==lo.id}">selected="selected"</c:if>>${lo.factoryName}</option>
				</c:forEach>
			</select>
		</div>
		<div class="col-xs-12 text-center" >
			<span class="runmi-btn runmi-primary" onclick="document.getElementById('selectItemForm').submit()">查询</span>
			<span class="runmi-primary runmi-btn search-btn"  onclick="doSelectItem()">确认</span>
		</div>

</div>
<div class="rect-fff table-warp">

	<div class="table-scroll">
	<table class="table-min-50">
		<tr>
			<th  width="40"><input type="checkbox" id="item_check_box_all"></th>
			<th>润米内部编码</th>
			<th>SKU名称</th>
			<th>商品69码</th>
			<th>品牌</th>
			<th>商品分类</th>
		</tr>
		<c:forEach items="${model.items}" var="item" varStatus="itemStatus">
				<tr>
					<td><input type="checkbox"
							   value="${item.id}"
							   skuCode="${item.sku_code}"
							   skuName="${item.sku_name}"
							   barCode="${item.bar_code}"
							   availableNum="${item.available_num}"
							   name="item_check_box"></td>
					<td><span>${item.sku_code}</span></td>
					<td><span>${item.sku_name}</span></td>
					<td><span>${item.bar_code}</span></td>
					<td><span>${item.brand_name}</span></td>
					<td><span>${item.categoryName}</span></td>
				</tr>
			</c:forEach>
		</table>
	</div>
	<vp:pages cpage="${model.cpage}" totalCount="${model.totalCount}"
			  pageSize="${model.pageSize}" />

</div>
</form>
<script>
    function doSelectItem() {
        var skuId = "";
        var skuCode="";
        var skuName="";
        var barCode="";
        var availableNum="";
        $("input[name='item_check_box']:checked").each(function(i) {
        	skuId = $(this).val();
        	skuCode= $(this).attr("skuCode");
        	skuName= $(this).attr("skuName");
        	barCode= $(this).attr("barCode");
        	availableNum= $(this).attr("availableNum");
        	//alert(skuId + skuName);
        	parent.catchSelectItem(skuId,skuCode,skuName,barCode,availableNum);
        });
        parent.closeSelect();
    }

    $("#item_check_box_all").bind("click",function(){
        $("input[name='item_check_box']").prop("checked",this.checked);
    });

    $(document).ready(function() {
        loadtree();
    });
    function loadtree() {
        postData = "1=1";
        var domainUrl = "${pageContext.request.contextPath}/item/category/cateview";
        $.ajax({
            type : "POST",
            url : domainUrl,
            data : postData,
            contentType : "application/x-www-form-urlencoded;charset=UTF-8",
            async : true, // 同步  true 异步。默认是异步
            error : function(resultdata) {
                //layer.closeAll();
            },
            success : function(resultdata) {
                $('#treediv').html(resultdata);
                $("#tree").treeview({
                    collapsed : true
                });
                $("#treediv").hide();
            }
        });
    }

    function showCategory() {
        $("#treediv").show();
    }
    function selectcategory(cateLevel, categoryId, category3Name,
                            category2Name, category1Name) {
        $('#cateId').val(categoryId);
        $('#catLevel').val(cateLevel);
        if (cateLevel == 1) {
            $('#catName').val(category1Name);
        }
        if (cateLevel == 2) {
            $('#catName').val(category1Name + ">" + category2Name);
        }
        if (cateLevel == 3) {
            $('#catName').val(
                category1Name + ">" + category2Name + ">" + category3Name);
        }
        $('#divCateName').html(
            category1Name + ">" + category2Name + ">" + category3Name);
        $("#treediv").hide();
    }
    $("#treediv1").hover(function() {
        // $(".content").show();
    }, function() {
        $("#treediv").hide();
    });
    
</script>